
# Create your views here.
from django.shortcuts import render, get_object_or_404
from polls.models import Imgs
from django.core.paginator import Paginator
from comment.models import Comment


def index(request):
    polls_all_list = Imgs.objects.all()
    paginator = Paginator(polls_all_list, 9)
    page_num = request.GET.get('page', 1)  # 获取url页面
    page_of_polls = paginator.get_page(page_num)

    return render(request, 'index.html', {'imgs': page_of_polls })


# 根据文章id进入页面
def con_detail(request, Imgs_id):
    con_item_list = get_object_or_404(Imgs, pk=Imgs_id)
    comment_list = Comment.objects.filter(post=Imgs_id)
    return render(request, 'con_detail.html', {'con_item_list': con_item_list, 'comment_list':comment_list})





